package com.ruoyi.iptv.live.type.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.iptv.live.type.domain.IptvLiveType;
import com.ruoyi.iptv.live.type.service.IIptvLiveTypeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 直播分类Controller
 * 
 * @author 玉念聿辉
 * @date 2021-10-20
 */
@Controller
@RequestMapping("/live/type")
public class IptvLiveTypeController extends BaseController
{
    private String prefix = "live/type";

    @Autowired
    private IIptvLiveTypeService iptvLiveTypeService;

    @RequiresPermissions("live:type:view")
    @GetMapping()
    public String type()
    {
        return prefix + "/type";
    }

    /**
     * 查询直播分类列表
     */
    @RequiresPermissions("live:type:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IptvLiveType iptvLiveType)
    {
        startPage();
        List<IptvLiveType> list = iptvLiveTypeService.selectIptvLiveTypeList(iptvLiveType);
        return getDataTable(list);
    }

    /**
     * 导出直播分类列表
     */
    @RequiresPermissions("live:type:export")
    @Log(title = "直播分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IptvLiveType iptvLiveType)
    {
        List<IptvLiveType> list = iptvLiveTypeService.selectIptvLiveTypeList(iptvLiveType);
        ExcelUtil<IptvLiveType> util = new ExcelUtil<IptvLiveType>(IptvLiveType.class);
        return util.exportExcel(list, "直播分类数据");
    }

    /**
     * 新增直播分类
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存直播分类
     */
    @RequiresPermissions("live:type:add")
    @Log(title = "直播分类", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IptvLiveType iptvLiveType)
    {
        return toAjax(iptvLiveTypeService.insertIptvLiveType(iptvLiveType));
    }

    /**
     * 修改直播分类
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        IptvLiveType iptvLiveType = iptvLiveTypeService.selectIptvLiveTypeById(id);
        mmap.put("iptvLiveType", iptvLiveType);
        return prefix + "/edit";
    }

    /**
     * 修改保存直播分类
     */
    @RequiresPermissions("live:type:edit")
    @Log(title = "直播分类", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IptvLiveType iptvLiveType)
    {
        return toAjax(iptvLiveTypeService.updateIptvLiveType(iptvLiveType));
    }

    /**
     * 删除直播分类
     */
    @RequiresPermissions("live:type:remove")
    @Log(title = "直播分类", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(iptvLiveTypeService.deleteIptvLiveTypeByIds(ids));
    }
}
